package com.ecr.hub.front.converter;

import java.text.DecimalFormat;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class FloatConverter implements Converter {

	DecimalFormat df = new DecimalFormat("########.00");

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		return null;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {

		Float f;
		try {
			f = (Float) value;
		} catch (ClassCastException e) {
			// Si double (jsf)
			f = Float.parseFloat(value.toString());
		}
		String s = df.format(f);
		return s;
	}
}
